package com.icity.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.icity.common.Result;
import com.icity.entity.User;
import com.icity.service.SystemService;

@RestController
@RequestMapping(value = "/admin/system")
public class LoginController {

	@Autowired
	private SystemService systemService;

	@RequestMapping(value = "/login")
	@ResponseBody
	public Result getMenuListByUser(HttpServletRequest request) {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		System.out.println(username+"--"+password);
		Map<Object,Object> map = new HashMap<Object,Object>();
		map.put("name", username);
		map.put("password", password);
		Result result = new Result();
		try {
			List<User> list = systemService.getUserInfo(map);
			if(list==null || list.size()==0){
				result.setCode("2");
				result.setMessage("用户名或密码错误");
			}else{
				result.setCode("1");
				result.setMessage(list.get(0).getUnique_code());
				result.setData(list.get(0));
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode("-1");
			result.setMessage("获取数据异常");
			return result;
		}
	}


}
